package com.itx.gatewayx.common.model;

import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 分页查询请求
 *
 * @author itx
 */
@Data
public class PageQuery implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 默认页码
     */
    public static final int DEFAULT_PAGE_NUM = 1;
    
    /**
     * 默认每页条数
     */
    public static final int DEFAULT_PAGE_SIZE = 10;
    
    /**
     * 最大每页条数
     */
    public static final int MAX_PAGE_SIZE = 100;

    /**
     * 当前页码
     */
    @NotNull(message = "页码不能为空")
    @Min(value = 1, message = "页码最小值为1")
    private Integer pageNum = DEFAULT_PAGE_NUM;

    /**
     * 每页数量
     */
    @NotNull(message = "每页条数不能为空")
    @Min(value = 1, message = "每页条数最小值为1")
    @Max(value = MAX_PAGE_SIZE, message = "每页条数最大值为" + MAX_PAGE_SIZE)
    private Integer pageSize = DEFAULT_PAGE_SIZE;
    
    /**
     * 排序字段
     */
    private String orderByColumn;

    /**
     * 排序方式 (asc/desc)
     */
    private String isAsc;
    
    public static PageQuery of() {
        return new PageQuery();
    }
    
    public static PageQuery of(Integer pageNum, Integer pageSize) {
        PageQuery pageQuery = new PageQuery();
        pageQuery.setPageNum(pageNum);
        pageQuery.setPageSize(pageSize);
        return pageQuery;
    }
} 